{% extends "forum/forumbase.html" %}

{% comment %}
#    Copyright 2012 New Mexico EPSCoR
#
#    This file is part of Teacher's P.E.T.
#
#    Teacher's P.E.T. is free software: you can redistribute it and/or modify
#    it under the terms of the GNU General Public License as published by
#    the Free Software Foundation, either version 3 of the License, or
#    (at your option) any later version.
#
#    Teacher's P.E.T. is distributed in the hope that it will be useful,
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#    GNU General Public License for more details.
#
#    You should have received a copy of the GNU General Public License
#    along with Teacher's P.E.T..  If not, see <http://www.gnu.org/licenses/>.
{% endcomment %}

{% load files %}

{% block title %} Messages | {{block.super}}{% endblock title %}

{% block css %}
    {{block.super}}
    <link rel="stylesheet" type="text/css" href="{{ STATIC_URL }}css/forum.css" >
{% endblock css %}

{% block content %}
<div class="forum-messages-index">
	<hr>
	<table class="forum-messages-header" border=0>
		<tr>
			<td class="forum-messages-create-new">
				{% if not ban or ban.message_ban < ban.BAN_NEW_MESSAGES %}
					<a class="forum-messages-button" href="{% course_url forum_send_message %}">Compose</a>
				{% endif %}
			</td>
			<td class="forum-messages-folder-title"><h2>{{folder|title}}</h2></td>

			<td class="forum-messages-navigation">
				{% if page.has_other_pages %}
					Page {{page.number}} of {{page.paginator.num_pages}}
					&nbsp;&nbsp;
					{% if page.has_previous %}<a href="{% course_url forum_view_folder_page folder=folder page='1' %}" title="Go to first page"><<</a>{% endif %}
					{% if page.number > 3 %}&nbsp;<a href="{% course_url forum_view_folder_page folder=folder page=page.number|add:"-3" %}">{{page.number|add:"-3"}}</a>{% endif %}
					{% if page.number > 2 %}&nbsp;<a href="{% course_url forum_view_folder_page folder=folder page=page.number|add:"-2" %}">{{page.number|add:"-2"}}</a>{% endif %}
					{% if page.number > 1 %}&nbsp;<a href="{% course_url forum_view_folder_page folder=folder page=page.number|add:"-1" %}">{{page.number|add:"-1"}}</a>{% endif %}
					&nbsp;{{page.number}}
					{% if page.pages_left >= 1 %}&nbsp;<a href="{% course_url forum_view_folder_page folder=folder page=page.number|add:"1" %}">{{page.number|add:"1"}}</a>{% endif %}
					{% if page.pages_left >= 2 %}&nbsp;<a href="{% course_url forum_view_folder_page folder=folder page=page.number|add:"2" %}">{{page.number|add:"2"}}</a>{% endif %}
					{% if page.pages_left >= 3 %}&nbsp;<a href="{% course_url forum_view_folder_page folder=folder page=page.number|add:"3" %}">{{page.number|add:"3"}}</a>{% endif %}
					{% if page.has_next %}&nbsp;<a href="{% course_url forum_view_folder_page folder=folder page=page.paginator.num_pages %}" title="Go to last page">>></a>{% endif %}
				{% endif %}
			</td>
		</tr>
	</table>
	<table class="forum-messages-table" border=0>
		<tr>
			<td class="forum-messages-index">
				<table class="forum-messages-index-table" border=0>
					<tr>
						<td>
							{% if request.user.unread_messages|length > 0 %}
								<a href="{% course_url forum_view_folder folder='inbox' %}"><b>Inbox&nbsp({{request.user.unread_messages|length}})</b></a>
							{% else %}
								<a href="{% course_url forum_view_folder folder='inbox' %}">Inbox</a>
							{% endif %}
						</td>
					</tr>
					<tr>
						<td>
							<a href="{% course_url forum_view_folder folder='drafts' %}">Drafts{% if user.draft_messages|length > 0 %}&nbsp({{user.draft_messages|length}}){% endif %}</a>
						</td>
					</tr>
					<tr><td><a href="{% course_url forum_view_folder folder='sent' %}">Sent</a></td></tr>
					<tr><td><a href="{% course_url forum_view_folder folder='trash' %}">Trash</a></td></tr>
					{% if request.user.block_list.all|length > 0 %}<tr><td><hr><a href="{% course_url forum_view_blocklist %}">Block&nbsp;List</a></td></tr>{% endif %}
				</table>
			</td>
			<td class="forum-messages-messages">
				<table class="forum-messages-messages-table" cellpadding=0 cellspacing=0 border=0>
				{% for msg in page.object_list %}
					{% get_file_list for msg as Files %}
					<tr class="forum-messages-row {% if forloop.last %}forum-messages-lastrow{% endif %}">
						{% if folder == "sent" %}
							{% with User=users|getitem:msg.recipient %}
							<td class="forum-messages-sender-avatar">
								<a href="{% course_url forum_view_message message_id=msg.id %}"><img src="{% if User.avatar %}{{User.avatar}}{% else %}{{STATIC_URL}}images/BlankAvatar.png{% endif %}" height="25"></a>
								<a class="{% if not msg.is_read and folder == 'inbox' %}forum-messages-unread-sender{% else %}forum-messages-read-sender{% endif %}" href="{% course_url forum_view_message message_id=msg.id %}">{{msg.recipient_name}}</a>
							</td>
							{% endwith %}
						{% else %}
							{% with User=users|getitem:msg.sender %}
							<td class="forum-messages-sender-avatar">
								<a href="{% course_url forum_view_message message_id=msg.id %}"><img src="{% if User.avatar %}{{User.avatar}}{% else %}{{STATIC_URL}}images/BlankAvatar.png{% endif %}" height="25"></a>
								<a class="{% if not msg.is_read and folder == 'inbox' %}forum-messages-unread-sender{% else %}forum-messages-read-sender{% endif %}" href="{% course_url forum_view_message message_id=msg.id %}">{{msg.sender_name}}</a>
							</td>
							{% endwith %}
						{% endif %}
						<td class="forum-messages-subject" rowspan="2">
							<a class="{% if not msg.is_read and folder == 'inbox' %}forum-messages-unread-subject{% else %}forum-messages-read-subject{% endif %}" href="{% course_url forum_view_message message_id=msg.id %}">
								{{msg.subject}} <span class="forum-messages-message-teaser">- {% if msg.message|length > 100 %}{{msg.message|strip_html|slice:":100"}}...{% else %}{{msg.message|strip_html}}{% endif %}</span>
							{% if Files %}<span class="forum-messages-subject-attachment"><img src="{{STATIC_URL}}images/attachment.png" height="15"></span>{% endif %}
							</a>
						</td>
						<td class="forum-messages-date {% if not msg.is_read and folder == 'inbox' %}forum-messages-unread-date{% else %}forum-messages-read-date{% endif %}" rowspan="2">
							<a href="{% course_url forum_view_message message_id=msg.id %}">
								{% if msg.sent_today %}{{msg.send_date|date:"g:i a"|spacify}}{% else %}{{msg.send_date|date:"M d, Y"|spacify}}{% endif %}
							</a>
						</td>
					</tr>
					<tr {% if forloop.last %}class="forum-messages-lastrow"{% endif %}>
						<td class="forum-messages-forum">{{msg.forum.title|spacify}}</td>
					
					</tr>
				{% endfor %}
				<tr><td class="forum-messages-message-invisible-row" colspan="100%"></td></tr>
				</table>
			</td>
		</tr>
	</table>
	<table class="forum-messages-header">
		<tr>
			<td class="forum-messages-create-new"></td>
			<td class="forum-messages-navigation">
				{% if page.has_other_pages %}
					Page {{page.number}} of {{page.paginator.num_pages}}
					&nbsp;&nbsp;
					{% if page.has_previous %}<a href="{% course_url forum_view_folder_page folder=folder page='1' %}" title="Go to first page"><<</a>{% endif %}
					{% if page.number > 3 %}&nbsp;<a href="{% course_url forum_view_folder_page folder=folder page=page.number|add:"-3" %}">{{page.number|add:"-3"}}</a>{% endif %}
					{% if page.number > 2 %}&nbsp;<a href="{% course_url forum_view_folder_page folder=folder page=page.number|add:"-2" %}">{{page.number|add:"-2"}}</a>{% endif %}
					{% if page.number > 1 %}&nbsp;<a href="{% course_url forum_view_folder_page folder=folder page=page.number|add:"-1" %}">{{page.number|add:"-1"}}</a>{% endif %}
					&nbsp;{{page.number}}
					{% if page.pages_left >= 1 %}&nbsp;<a href="{% course_url forum_view_folder_page folder=folder page=page.number|add:"1" %}">{{page.number|add:"1"}}</a>{% endif %}
					{% if page.pages_left >= 2 %}&nbsp;<a href="{% course_url forum_view_folder_page folder=folder page=page.number|add:"2" %}">{{page.number|add:"2"}}</a>{% endif %}
					{% if page.pages_left >= 3 %}&nbsp;<a href="{% course_url forum_view_folder_page folder=folder page=page.number|add:"3" %}">{{page.number|add:"3"}}</a>{% endif %}
					{% if page.has_next %}&nbsp;<a href="{% course_url forum_view_folder_page folder=folder page=page.paginator.num_pages %}" title="Go to last page">>></a>{% endif %}
				{% endif %}
			</td>
		</tr>
	</table>
</div>
{% endblock content %}